<?php
/**
 * Description of AnswerController
 *
 * @author hoangle
 */
class AnswerController extends Zend_Controller_Action {
    
    private $sessionLogin;

    public function init() {
        //Check session
        $this->sessionLogin = new Zend_Session_Namespace('User');
        //Check session
        if (empty($this->sessionLogin->accountinfo)) {
            $this->_redirect('/');
            exit;
        }
    }

    /**
     * @desc Answer List
     */
    public function indexAction() {
        $this->view->headTitle('Danh sách câu trả lời');
        //session userid
        $userid = $this->sessionLogin->accountinfo['userid'];

        $yesterday = date('Y-m-d',strtotime('-2 day'));

        //Get list answer of user
        $result = Service_Model::factory('UserQuestion', 'getUserQuestionByUserId', array('userid' => $userid,
            'yesterday' => $yesterday), 'frontend');

        //Get question
        $arrQuestion = (array) Service_Model::factory('Question', 'getQuestion', NULL, 'frontend');
        foreach ($arrQuestion as $val) {
            $arrRestQuest[$val['mackid']] = $val['mackname'];
        }

        $this->view->question = $arrRestQuest;
        $this->view->answer = $result;
    }

   /**
     * @desc Refuse
     */
    public function refuseAction() {
        $userid = $this->sessionLogin->accountinfo['userid'];

        $id = $this->_request->getParam('id');

        $arrUserQuestion = (array) Service_Model::factory('UserQuestion', 'getUserQuestionById', $id, 'frontend');

        $createtime = date('Y-m-d', strtotime($arrUserQuestion['createtime']));

        //Get question user
        if ($arrUserQuestion['refuse_flag'] == 1 && $arrUserQuestion['refuse'] == 0 &&
                $arrUserQuestion['answer_flag'] == 1 && $arrUserQuestion['count_refuse'] < 1) {
            $result = (array) Service_Model::factory('UserQuestion', 'refuseUserQuestionAlreadyReply',
                            array('userid' => $userid, 'id' => $id), 'frontend');
        }
        //End

        $this->_redirect('answer');
    }
    
   
}

?>
